<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>

<html>
    <head>
		<%@ include file="/WEB-INF/views/include/common.jsp" %>
		<meta name="AUTHOR" content="QroTech Inc." />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
		<meta http-equiv="PRAGMA" content="NO-CACHE">
		<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>큐로넷::위치관제시스템</title>
		
		<link rel="stylesheet" href="${cssUrl}/header-1.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/fancy_table.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/menu.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/table.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/button.css" type="text/css" />
		<!--<link rel="stylesheet" href="${cssUrl}/m-310.css" type="text/css" />-->
		<link rel="stylesheet" href="${cssUrl}/m-300-1.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/groupManage_popup_box.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/m-340.css" type="text/css" />
<!-- 		<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script> -->
		<script src="${jsUrl}/m-340.js"></script>
		
		
    </head>
    <body onload="init();">
    	<div id="overlay" class="overlay" >
    	</div><!-- contentWrapper end -->
    	<div class="headerContent">
	
		<div class="pageHeader">
			<%@ include file="/WEB-INF/views/include/logoLink.jsp" %>
			<div id="pageNav">
				<ul>
<!-- 					<a href="m-100.html" class="togglerHeader"><li class="hmenu0" id="hdmenu0"></li></a> -->
<!-- 					<a href="#" class="togglerHeader"><li class="hmenu1" id="hdmenu1"></li></a> -->
<!-- 					<a href="m-300.html" class="togglerHeader"><li class="hmenu2" id="hdmenu2"></li></a> -->
<!-- 					<a href="#" class="togglerHeader"><li class="hmenu3" id="hdmenu3"></li></a> -->
					<%@ include file="/WEB-INF/views/include/mainNaviStyle2.jsp" %>
				</ul>
			</div>
			<div id="pageNavRight">
				<%@ include file="/WEB-INF/views/include/titleLink.jsp" %>
			</div>
		</div>
			<div class="header_line"></div>
		</div><!--header end-->	
	
        
        	<div class="secondMenu" >
					<div id="menu">
						<ul>
							<%@ include file="/WEB-INF/views/include/innerNavi.jsp" %>
						</ul>
					</div>
				</div><!-- second menu end -->
			
			<div class="m340height">	
						
			<div class="mainContent">	
				<div class="searchInfo">
					<ul>
						<li class= "locationInfo"><span>사용자 정보</span></li>
						<li class="totalSearchNum"><span id="cnt"></span>명 / 총 <c:out value="${totalCnt}" />명</li>
						<li class='textSearch'>사용자 검색</li>
						<li class="choices">
							<select name="searchType" id="searchType">
								<option value="1">사용자명</option>
								<option value="2">아이디</option>
								<option value="3">소속</option>
								<option value="4">관리그룹</option>
							</select>
						</li>
						<li class="inputSearch"><input type="text" id="searchName" name="searchName"></li>
						<li class="search_button"><a onClick="getUserList()"><img id="popup" src="${imgUrl}/black_box.png"></a></li>
						
					</ul>
					<div class="last"><a onclick="javscript:openQuestionPopup('http://www.qronet.co.kr/help/qronet_help.html#ManageUser')"><img src="${imgUrl}/question_mark.png"/></a></div>
					<div class="last2"><a class="button1 popup_open" id="4">새사용자 등록</a></div>
				</div><!-- searchInfo end -->
				<div class="leftAndRight">
					<div class="leftContent">
						<div class="insideContentLeft">
							<div class="chart300"> 
							
								<div class="chart_head" >
									<table  valign="top" cellpadding="0" cellspacing="0"> 
										<tr valign="top" >
											
											<th width="90px">소속</th>
											<th width="90px">사용자명</th>
											<th width="80px">아이디</th>
											<th width="80px">등록일</th>
											<th width="145px">최종로그인</th>
											<th width="*">차단</th>
										</tr>	
										
									</table>
								</div><!--chart_head end-->
								<div class="chart_body">
									<table cellpadding="0" cellspacing="0" id="userList"> 
										<tr valign="top" onClick="setData(this)">
											<td width="90px" id="deptName"></td>
											<td width="90px" id="name"></td>
											<td width="80px" id="loginID"></td>
											<td width="80px" id="regiDate"></td>
											<td width="145px" id="loginDate"></td>
											<td width="*"><input type="checkbox" id="lock" name="lock" value="y" onClick="updateLock(this)"></td>
											<td style="display:none;"><input type="hidden" id="userCode"/>
																	  <input type="hidden" id="deptCode"/>
																	  <input type="hidden" id="locked" /></td>
										</tr>
										
									</table>	
								</div><!-- chart_body end -->
							</div><!-- chart300 end-->
						</div>
					</div>
					<div class="rightContent">
						<div class="insideContentRight">
							<div class="content">
									
									<div class="top">
											<span class="plate">사용자명 : <span id="detailInfoName"></span></span>
											<input type="hidden" id="detailUserCode"/>
											<input type="hidden" id="tempDeptCode" value="0"/>
									</div>
									<div class="scroll">
									<div class="tableTitleA">사용자 등록 정보<a class="button1 save" onClick="deleteUserListDetail()">삭제</a></div>
									<div class="map_table">
										<table class="content1" cellpadding="0" cellspacing="0">
											<tr >
												<th class="table_title_color">아이디</th>
												<td><span id="detailLoginID"></span></td>
											</tr>
											<tr>
												<th class="table_title_color">등록일</th>
												<td><span id="detailRegiDate"></span></td>
											</tr>
											<tr>
												<th class="table_title_color">최근로그인시각</th>
												<td><span id="detailLoginDate"></span></td>
											</tr>
											
										</table>
									</div>
									<div class="tableTitleA">사용자 정보 <a class="button1 save" onClick="updateUserListDetail()">저장</a></div>
									<div class="map_table">
									<form id="theForm" name="theForm">
										<table class="content1" cellpadding="0" cellspacing="0">
											<tr >
												<th class="table_title_color">사용자명</th>
												<td><input type="text" id="detailName"></td>
											</tr>
											<tr>
												<th class="table_title_color">소속 </th>
												<td>
													<select id="detailDeptCode" name="detailDeptCode">
														<option value="0">미지정</option>
													</select>
													<a class="button1 popup_open" id="1">소속관리...</a>
												</td>
											</tr>
											<tr >
												<th class="table_title_color">운전자핸드폰</th>
												<td><input type="text" id="detailHandPhone"><p>*숫자로만 입력하세요.</p></td>
											</tr>
											<tr >
												<th class="table_title_color">일반전화</th>
												<td><input type="text" id="detailPhone"><p>*숫자로만 입력하세요.</p></td>
											</tr>
											<tr >
												<th class="table_title_color">이메일</th>
												<td><input type="text" id="detailEmail"></td>
											</tr>
											<tr >
												<th class="table_title_color">비밀번호</th>
												<td class="pass"><a class="button1 popup_open" id="5"> 비밀번호 변경...</a><input type="hidden" id="detailLoginPW" name="detailLoginPW"/> </td>
											</tr>
											<tr>
												<th class="table_title_color">관리그룹</th>
												<td>
													<div class="groupListBox" id="detailGroupList">
														<!-- 관리그룹1<br />
														관리그룹2<br />
														관리그룹3<br />
														관리그룹4<br /> -->
													</div>
													<div class="rightBtn">
														<p><a class="button1  popup_open" id="3"> 관리그룹  변경</a></p>
														<p><a class="button1  popup_open" id="2">그룹관리...</a></p>
													</div>
													
												</td>
											</tr>
											<tr >
												<th class="table_title_color">사용권한</th>
												<td class="checkboxCenter">
													<p><input type="checkbox" value="y" name="privCarControl" id="detailPrivCarControl"> 차량 제어 권한</p>
													<p><input type="checkbox" value="y" name="privSMS" id="detailPrivSMS"> SMS 발송 권한</p>
												</td>
											</tr>
											<tr >
												<th class="table_title_color">메모</th>
												<td class="textarea"><textarea id="detailMemo"></textarea> </td>
											</tr>
											
										</table>
									</form>
									</div>
								</div><!--scroll end -->
							</div><!--content end -->
						</div><!--insideRightContent end -->
					
					</div><!--rightContent end -->
					
				</div><!--leftAndRight-->
	        	
        	
		</div> <!-- mainContent end -->
		</div> <!-- m300height end -->
		<div class="chart_footer">
		    <div class="footerCenter">
		       <span>Copyright ⓒ 2013 Qrotech Co.,Ltd. All rights reserved.</span>
		    </div>
	 </div>	<!-- footer end-->	
	
	<div class="m340_popup1" id="popup1">
		 <div class="groupManage_popup_box" >
			<div class="tableTitleA">소속관리<img class="popup_close" src="${imgUrl}/popup_close.png"></div>
			<div class="content">
				<div class="info"><input type="text" name="popupDeptName" id="popupDeptName"><a class="button2" onClick="registDeptInfo()">추가</a></div>
					<div class="map_table">
						<table class="content1" cellpadding="0" cellspacing="0"> 
							<tr valign="top" >
								<th class="table_title_color line" width="50px"><a class="button2" onClick="deleteDeptInfo()">삭제</a></th>
								<th class="titleCenter">소속명</th>
							</tr>
						</table>
					</div>
					<div class="map_table_body">
						<table class="content1" cellpadding="0" cellspacing="0" id="deptList">
									<!-- <tr valign="top" >
										<td width="50px" class="line"><input type="checkbox"></td>
										<td>관리부 </td>
									</tr>
									<tr valign="top" >
										<td width="50px" class="line"><input type="checkbox"></td>
										<td>연구소</td>
									</tr>
									<tr valign="top" >
										<td width="50px" class="line"><input type="checkbox"></td>
										<td>마케팅부</td>
									</tr>
									<tr valign="top" >
										<td width="50px" class="line"><input type="checkbox"></td>
										<td>마케팅부</td>
									</tr>
									<tr valign="top" >
										<td width="50px" class="line"><input type="checkbox"></td>
										<td>마케팅부</td>
									</tr>
									<tr valign="top" >
										<td width="50px" class="line"><input type="checkbox"></td>
										<td>마케팅부</td>
									</tr> -->
											
						</table>	
					</div><!-- map_table end -->
						
				  <p>&nbsp;</p>
					<div class="Rowbtn2"><a class="button2" onClick="popupClose(1)">닫기</a></div>
					</div><!-- content end-->	
				</div>	<!--groupManage_popup_box-->	
		</div><!--m340_popup5-->
	<div class="m340_popup2" id="popup2">
	<div class="groupManage_popup_box" >
		<div class="tableTitleA ">그룹관리<img class="popup_close" src="${imgUrl}/popup_close.png"></div>
		<div class="content">
			<div class="info"><input type="text" id="newCarGroupName"><a class="button2" onClick="registCarGroup()">추가</a></div>
				<div class="map_table">
						
					<table class="content1" cellpadding="0" cellspacing="0"> 
						<tr valign="top" >
							<th class="table_title_color line" width="50px"><a class="button2" onClick="deleteCarGroup()">삭제</a></th>
							<th class="titleCenter">관리그룹명</th>
						</tr>
					</table>
				</div>
				<div class="map_table_body">
					<table class="content1" cellpadding="0" cellspacing="0" id="carGroupList">
								<!-- <tr valign="top" >
									<td width="50px" class="line"><input type="checkbox"></td>
									<td>관리그룹 1</td>
								</tr>
								<tr valign="top" >
									<td width="50px" class="line"><input type="checkbox"></td>
									<td>위험물차량</td>
								</tr>
								<tr valign="top" >
									<td width="50px" class="line"><input type="checkbox"></td>
									<td>그냥 차량</td>
								</tr>
								<tr valign="top" >
									<td width="50px" class="line"><input type="checkbox"></td>
									<td>관리그룹 1</td>
								</tr>
								<tr valign="top" >
									<td width="50px" class="line"><input type="checkbox"></td>
									<td>위험물차량</td>
								</tr>
								<tr valign="top" >
									<td width="50px" class="line"><input type="checkbox"></td>
									<td>그냥 차량</td>
								</tr> -->
										
					</table>	
				</div><!-- map_table end -->
				<p>&nbsp;</p>
				<div class="Rowbtn2"><a class="button2" onClick="popupClose(2)">닫기</a></div>
				</div><!-- content end-->	
			</div>	<!--groupManage_popup_box-->
		</div>	<!--m340_popup2-->
			
			<div class="m340_popup4" id="popup4">
				<div class="groupManage_popup_box" >
					<div class="tableTitleA ">새사용자 등록<img class="popup_close" src="${imgUrl}/popup_close.png"></div>
						<div class="content">
							<div class="map_table">
								<form name="regiForm" id="regiForm">
								<input type="hidden" id="cnt"/>
								<table class="content1" cellpadding="0" cellspacing="0"> 
									<tr valign="top" >
										<th>사용자명</th>
										<td><input type="text" name="name"></td>
									</tr>
									<tr valign="top" >
										<th>아이디</th>
										<td><input type="text" name="loginID"> <a onClick="checkLoginID()" class="button1">중복확인</a></td>
									</tr>
									<tr valign="top" >
										<th>비밀번호</th>
										<td><input type="password" name="loginPW"><p>*32자 이내</p>
										</td>
									</tr>
									<tr valign="top" >
										<th>비밀번호확인</th>
										<td><input type="password" name="loginPW1"></td>
									</tr>
								</table>
								</form>
							</div>
						<p style="margin-left:20px;font-weight:bold;">* 새사용자 등록후 반드시 사용권한 등 정보를 수정하세요.</p>
					
					<div class="Rowbtn2"><a onClick="registUserListDetail()" class="button2">확인</a><a class="button2 last" onClick="popupClose(4)">취소</a></div>
				</div><!-- content end-->	
			</div>	<!--groupManage_popup_box4-->
		</div>	<!--m340_popup4-->
		<div class="m340_popup5" id="popup5">
				<div class="groupManage_popup_box" >
					<div class="tableTitleA ">비밀번호 변경<img class="popup_close" src="${imgUrl}/popup_close.png"></div>
						<div class="content">
							<div class="map_table">
								<table class="content1" cellpadding="0" cellspacing="0"> 
									<tr valign="top" >
										<th>비밀번호</th>
										<td><input type="password" name="popupLoginPW" id="popupLoginPW"></td>
									</tr>
									<tr valign="top" >
										<th>비밀번호확인</th>
										<td><input type="password" name="popupLoginPW1" id="popupLoginPW1"></td>
									</tr>
								</table>
							</div>
						<div class="Rowbtn2"><a class="button2" onClick="updateLoginPW()">확인</a><a class="button2 last" onClick="popupClose(5)">취소</a></div>
				</div><!-- content end-->	
			</div>	<!--groupManage_popup_box4-->
		</div>	<!--m340_popup5-->
		<div class="m340_popup3" id="popup3">	
		<div class="m310_popup_box">
			<div class="tableTitleA ">대상 그룹 선택 (관심지역명)<img class="popup_close" src="${imgUrl}/popup_close.png"></div>
				<div class="content">
					<ul>
						<li>사용자에게 권한이 부여된 관리그룹을  오른쪽으로 추가합니다.</li>
						<li>관리그룹은 차량관리에서 추가할 수 있습니다.</li>
					</ul>
				
				<div class="wrapper">
						<div class="left">
							<div class="title1">추가가능그룹</div>
							<div class="scroll">
								<table class="content1"  id="leftGroup">
									<tr onClick="setLeftCarGroupCode(this)" style="cursor:pointer;">
										<td id="groupName">관리그룹 1</td>
										<td style="display:none;"><input type="hidden" id="userCarGroupCode">
									</tr>
								</table>
							</div>
						</div>
						<div class="middle">
							<p><a class="button2" onClick="addGroup()">추가 ></a></p>
							<p><a class="button2" onClick="deleteGroup()">&lt; 제외</a></p>
						</div>
						<div class="right">
							<div class="title2">추가된 그룹</div>
							<div class="scroll">
								<table class="content1 space"  id="rightGroup">
									<tr onClick="setRightCarGroupCode(this)" style="cursor:pointer;">
										<td id="groupName">미지정</td>
										<td style="display:none;"><input type="hidden" id="userCarGroupCode"></td>
									</tr>
								</table>
							</div>
						</div>
					</div>
				<div class="Rowbtn2"><a class="button2" onClick="registUserCarGroup()">확인</a><a class="button2 last" onClick="popupClose(3)">취소</a></div>
			</div><!-- content end-->	
		</div>	<!--m310_popup_box-->
	</div>	<!--m340_popup_box-->
	<script language="javascript">
		var _this = this;
		function init() {
			getUserList();
			getDeptList();
			getCarGroupList();
		}
		function getUserList() {
			_this.table1 = tableSync('userList');
			try{
	    		var url="getUserList.json";
	    		var searchType = $("select[name=searchType]").val();
	    		var searchName = $('#searchName').val();
	    		var param = "searchType="+searchType+"&searchName="+searchName;
	    		AjaxPost(url, param, function(data){
	    			 jsonLog(data.userList);
	    			 if (data.userList.length > 0) {
	    				 $('#cnt').text(data.userList.length);
	    				 $(data.userList).each(function(ind) {
	    					 if (this['regiDate'] != null) {
	    					 	this['regiDate'] = formatter.dateFormatYYYYMMDD(new Date(this['regiDate']));
	    					 } else {
	    						 this['regiDate'] = ""; 
	    					 }
	    					 if (this['loginDate'] != null) {
	    					 	this['loginDate'] = formatter.dateFormatYYYYMMDDHHMMSS2(new Date(this['loginDate']));
	    					 } else {
	    					 	this['loginDate'] = "";
	    					 }
	    					 
	    					 if (this['deptName'] == null || this['deptName'] == '') {
	    						 this['deptName'] = "미지정";
	    					 }
	    				 });
	    				_this.table1.tableAutoSync(data.userList);
		    			 selectedCheckbox();
	    			 }
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function selectedCheckbox() {
			$("#userList > tbody > tr").each(function() {
				if($(this).find("#locked").val() == 'y') {
					$(this).find("#lock").prop('checked', true);
				}	
			});
		}
		function getUserListDetail() {
			try{
	    		var url="getUserListDetail.json";
	    		var detailUserCode = $("#detailUserCode").val();
	    		var param = "userCode="+detailUserCode;
	    		AjaxPost(url, param, function(data){
// 	    			 jsonLog(data.userListDetail);
	    			 if (data.userListDetail != null) {
	    				 $('#detailInfoName').text(data.userListDetail['name']);
	    				 $('#detailLoginID').text(data.userListDetail['loginID']);
	    				 $('#detailRegiDate').text(formatter.dateFormatYYYYMMDD(new Date(data.userListDetail['regiDate'])));
	    				 if (data.userListDetail['loginDate'] != null) {
	    				 	$('#detailLoginDate').text(formatter.dateFormatYYYYMMDDHHMMSS2(new Date(data.userListDetail['loginDate'])));
	    				 } else {
	    					 $('#detailLoginDate').text(""); 
	    				 }
	    				 $('#detailName').val(data.userListDetail['name']);
	    				 $('#detailHandPhone').val(data.userListDetail['handPhone']);
	    				 $('#detailPhone').val(data.userListDetail['phone']);
	    				 
	    				 $('#popupLoginPW').val(data.userListDetail['loginPW']);
	    				 $('#popupLoginPW1').val(data.userListDetail['loginPW']);
	    				 $('#detailLoginPW').val(data.userListDetail['loginPW']);
	    				 $('#detailDeptCode option[value="'+data.userListDetail['deptCode']+'"]').prop('selected', true);
	    				 $('#detailEmail').val(data.userListDetail['email']);
	    				 $('#detailMemo').val(data.userListDetail['memo']);
	    				 
	    				 if(data.userListDetail['privCarControl'] == 'y') {
	    					 $("input[name='privCarControl']").prop("checked", "checked");
	    				 } else {
	    					 $("input[name='privCarControl']").prop("checked", "");
	    				 }
	    				 if(data.userListDetail['privSMS'] == 'y') {
	    					 $("input[name='privSMS']").prop("checked", "checked");
	    				 } else {
	    					 $("input[name='privSMS']").prop("checked", "");
	    				 }
	    			 }
	    			 getUserCarGroupList(detailUserCode);
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function setData(tr) {
			clearData();
			$("#detailUserCode").val($(tr).find("#userCode").val());
			$('#tempDeptCode').val($(tr).find("#deptCode").val());
			getUserListDetail();
		}
		
		function clearData() {
			$('#detailInfoName').text("");
			$('#detailUserCode').val();
			$('#detailLoginID').text("");
			$('#detailRegiDate').text("");
			$('#detailLoginDate').text("");
			$('#theForm')[0].reset();
		}
		
		function deleteUserListDetail() {
			var userCode = $('#detailUserCode').val();
			if (userCode == '') {
				alert('사용자를 선택하세요.');
				return;			
			}
			try{
	    		var url="deleteUserListDetail.json";
	    		var param = "userCode="+userCode;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getUserList();
    				 clearData();
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function updateUserListDetail() {
			var userCode = $("#detailUserCode").val();
			if(userCode == '') {
				alert('사용자를 선택하세요.');
				return;
			}
			var param = {};
			
			param['name'] = $("#detailName").val();
			param['deptCode'] = $("select[name=detailDeptCode]").val();
			param['handPhone'] = $("#detailHandPhone").val();
			param['phone'] = $("#detailPhone").val();
			param['email'] = $("#detailEmail").val();
			param['loginPW'] = $("#detailLoginPW").val();
			param['memo'] = $("#detailMemo").val();
			param['userCode'] = userCode;
			param['privCarControl'] = $("input[name=privCarControl]:checkbox:checked").val();
			param['privSMS'] = $("input[name=privSMS]:checkbox:checked").val();
			try{
	    		var url="updateUserListDetail.json";
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getUserList();
    				 //clearData();
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function registUserListDetail() {
			var cnt = $('#cnt').val();
			if(cnt == '') {
				alert('아이디 중복체크를 해주세요.');
				return;
			}
			if(cnt != 0){
				alert('사용중인 아이디입니다.');
				return;
			}
			try{
	    		var url="registUserListDetail.json";
	    		var param = $('#regiForm').serialize();
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getUserList();
    				 $('#regiForm')[0].reset();
    				 popupClose(4);    				 
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function checkLoginID() {
			try{
	    		var url="checkLoginID.json";
	    		var param = $('#regiForm').serialize();
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 $("#cnt").val(data.cnt);
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function updateLoginPW(){
			var userCode = $('#detailUserCode').val();
			
			if(userCode == '') {
				alert('사용자를 선택하세요.');
				return;
			}
			
			if ($('#popupLoginPW').val() != $('#popupLoginPW1').val()) {
				alert('비밀번호가 맞지 않습니다.');
				$('#popupLoginPW1').focus();
				return;
			}
			$('#detailLoginPW').val($('#popupLoginPW').val());
			popupClose(5);
			/* try{
	    		var url="updateLoginPW.json";
	    		var param = "userCode="+userCode+"&loginPW="+$('#popupLoginPW').val();
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 popupClose(5);    				 
	    		});
	    	}catch(e){
	    		//logs(e);
	    	} */
		}
		
		function getDeptList() {
			var rtnVal = "";
			var url = "getDeptList.json";
			var param = "";
			$("select[name='detailDeptCode'] option").remove();
			$('#detailDeptCode').append("<option value=0>미지정</option>");
			AjaxPost(url, param, function(data){
	   			 if (data.deptList.length > 0) {
	   				 $(data.deptList).each(function(ind) {
	   					 //소속관리 리스트
	   					 rtnVal += "<tr valign='top'>";
	   					 rtnVal += "	<td width='50px' class='line'><input type='checkbox' name='deptCode' value='"+this['deptCode']+"'></td>";
	   					 rtnVal += "	<td>"+this['deptName']+"</td>";
	   					 rtnVal += "</tr>";
	   					 
	   					 //소속관리 selectbox
	   					 $('#detailDeptCode').append("<option value="+this['deptCode']+">"+this['deptName']+"</option>");
	   				 });
	   			 }
	   			 $('#deptList').html(rtnVal);
	   			 $('#detailDeptCode option[value="'+$('#tempDeptCode').val()+'"]').prop('selected', true);
   			});
		}
		
		function registDeptInfo() {
			var deptName = $('#popupDeptName').val();
			if(deptName == '') {
				alert('소속명을 입력하세요.');
				return;
			}
			try{
	    		var url="registDeptInfo.json";
	    		var param = "deptName="+deptName;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getDeptList();
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function deleteDeptInfo() {
			var codes = "";  
		    $("input[name=deptCode]:checkbox:checked").each(function (index) {  
		    	codes += $(this).val()+",";  
		    });
		    
		    if(codes == ""){
		    	alert('삭제할 대상이 없습니다.');
		    	return;
		    }
		    
		    var lastIndex = codes.lastIndexOf(',');
		    var deptCodes = codes.substring(0, lastIndex);
		    
		    try{
	    		var url="deleteDeptInfo.json";
	    		var param = "deptCodes="+deptCodes;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getDeptList();
    				 getUserList();
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function getCarGroupList() {
			var rtnVal = "";
			var url = "getCarGroupList.json";
			var param = "";
			AjaxPost(url, param, function(data){
	   			 if (data.carGroupList.length > 0) {
	   				 $(data.carGroupList).each(function(ind) {
	   					 //소속관리 리스트
	   					 rtnVal += "<tr valign='top'>";
	   					 rtnVal += "	<td width='50px' class='line'><input type='checkbox' name='carGroupCode' value='"+this['carGroupCode']+"'></td>";
	   					 rtnVal += "	<td>"+this['groupName']+"</td>";
	   					 rtnVal += "</tr>";
	   				 });
	   			 }
	   			 $('#carGroupList').html(rtnVal);
   			});
		}
		
		function registCarGroup() {
			var carGroupName = $('#newCarGroupName').val();
			if(carGroupName == '') {
				alert('그룹명을 입력하세요.');
				return;
			}
			try{
	    		var url="registCarGroup.json";
	    		var param = "groupName="+carGroupName;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getCarGroupList();
    				 $('#newCarGroupName').val("");
    				 getUserCarGroupList($('#detailUserCode').val());
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function deleteCarGroup() {
			var codes = "";  
		    $("input[name=carGroupCode]:checkbox:checked").each(function (index) {  
		    	codes += $(this).val()+",";  
		    });
		    
		    if(codes == ""){
		    	alert('삭제할 대상이 없습니다.');
		    	return;
		    }
		    
		    var lastIndex = codes.lastIndexOf(',');
		    var carGroupCodes = codes.substring(0, lastIndex);
		    
		    try{
	    		var url="deleteCarGroup.json";
	    		var param = "carGroupCodes="+carGroupCodes;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
    				 getCarGroupList();
    				 $('#newCarGroupName').val("");
    				 getUserCarGroupList($('#detailUserCode').val());
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
		}
		
		function getUserCarGroupList(userCode) {
			
			var url="getUserCarGroupList.json"; 
    		var param = "userCode="+userCode;
    		var rtnVal = "", rtnVal1 = "";
   			$("#detailGroupList").html("");
    		AjaxPost(url, param, function(data){
    			 if(data.leftGroup.length > 0) {
					 _this.table1 = tableSync('leftGroup');
					 $(data.leftGroup).each(function(ind) {
						 this['userCarGroupCode'] = this['carGroupCode'];
					 });
					 _this.table1.tableAutoSync(data.leftGroup);
				 }
    			 if(userCode > 0) {
					 _this.table1 = tableSync('rightGroup');
					 $(data.rightGroup).each(function(ind) {
						rtnVal1 += this['groupName']+"<br>";
						 this['userCarGroupCode'] = this['carGroupCode'];
					 });
					 $("#detailGroupList").html(rtnVal1);
					 _this.table1.tableAutoSync(data.rightGroup);
					 if(data.rightGroup.length == 0) {
    					 rtnVal += "<tr id='noGroup' onClick='setRightCarGroupCode(this)' style='cursor:pointer;'>";
						 rtnVal += 		"<td id='groupName'>미지정</td>";
						 rtnVal += 		"<td style='display:none;''><input type='hidden' id='userCarGroupCode' value='0'></td>";
						 rtnVal += "</tr>";
						 $('#rightGroup').html(rtnVal);
    				 }
    			 }
    		});			 
		}
		
		var leftSelectedTr = null, rightSelectedTr = null;
		function setLeftCarGroupCode(tr){
			if(tr != null) {
				$(leftSelectedTr).find("td").css("background-color","white");
				$(tr).find("td").css("background-color","grey");
				leftSelectedTr = tr;
			}
		}
		
		function setRightCarGroupCode(tr){
			if (tr != null) {
				$(rightSelectedTr).find("td").css("background-color","white");
				$(tr).find("td").css("background-color","grey");
				rightSelectedTr = tr;
			}
		}
		
		function addGroup() {
			$(leftSelectedTr).remove();
			$(leftSelectedTr).find("td").css("background-color","white");
			$('#rightGroup').append($(leftSelectedTr).attr("onClick", "setRightCarGroupCode(this)"));
			$('#noGroup').remove();
		}
		
		function deleteGroup() {
			$(rightSelectedTr).remove();
			$(rightSelectedTr).find("td").css("background-color","white");
			if($(rightSelectedTr).find("#groupName").text() != "미지정") {
				$('#leftGroup').append($(rightSelectedTr).attr("onClick", "setLeftCarGroupCode(this)"));
			}
		}
		
		function registUserCarGroup() {
			var userCode = $("#detailUserCode").val();
			var carGroupCode = "";
			$('#rightGroup tr').each(function() {
				carGroupCode += $(this).find('#userCarGroupCode').val() + ":" ;
			});
			
			try {
				var lastIndex = carGroupCode.lastIndexOf(':');
				carGroupCode = carGroupCode.substr(0,lastIndex);
				
	    		url="registUserCarGroup.json";
	    		param = "userCode="+userCode+"&carGroupCodeStr="+carGroupCode;
	    		AjaxPost(url, param, function(data){
	    			alert(data.msg);
	    			popupClose(3);
	    			getUserCarGroupList($('#detailUserCode').val());
	    		});
			} catch(e) {
				
			}
		}
		
		function updateLock(chk) {
			var locked = 'n';
			var userCode = $(chk).parent().parent().find("#userCode").val();
			if ($(chk).is(":checked")) {
				locked = $(chk).val();
			}
			
			try{
	    		var url="updateLocked.json";
	    		var param = "userCode="+userCode+"&locked="+locked;
	    		AjaxPost(url, param, function(data){
    				 alert(data.msg);
	    		});
	    	}catch(e){
	    		//logs(e);
	    	}
			
		}
		function popupClose(num) {
			$('#overlay').css('display', 'none');
			if (num == 1) {
				$('#popup1').hide();
			} else if (num == 2) {
		       	$('#popup2').hide();
			} else if (num == 3) {
				$('#popup3').hide();
			} else if (num == 4) {
		       	$('#popup4').hide();
			} else if (num == 5) {
				$('#popup5').hide();
			}
		}
		
	</script>
  </body>
</html>
